import React, {useEffect, useState} from 'react';
import {Modal, Form, Select} from "antd";
import {roomStatusList} from "@/pages/constant";

function UseFormModal({url,callback=()=>{}}) {
    const [open,setOpen] = useState(false),
        [loading,setLoading] = useState(false),
        [form] = Form.useForm();
    function onCancel(){
        setOpen(false)
    }
    async function onOk(){
        const values = await form.validateFields();
        setLoading(true)
        console.log(values)
        console.log(form.getFieldsValue())
        return ;
        try {
            const result = await ax.post(url,{
                ...values,
            })
            onCancel();
            callback();
            return result;
        }finally {
            setLoading(false);
        }
    }
    useEffect(()=>{
        if(open){
            form.setFieldsValue(open)
        }
    },[open])
    return {
        FormDom:<Modal
            open={open}
            onCancel={onCancel}
            confirmLoading={loading}
            onOk={onOk}
            {...props}
        >
            <Form
                form={form}
            >
                <Form.Item
                    label={"修改状态"}
                >
                    <Select options={roomStatusList.slice(1)} placeholder={"请选择"} allowClear/>
                </Form.Item>
            </Form>
        </Modal>,
        setOpen,
        onOk
    }
}

export default UseFormModal;